#import "ALEntryFilter.h"

static NSString* const ALEntryFilterIntermediateKeyPathTag = @"tags";
static NSString* const ALEntryFilterPrimaryKeyPathTag = @"title";
static NSString* const ALEntryFilterPrimaryKeyPathCreator = @"creator";
static NSString* const ALEntryFilterPrimaryKeyPathCreationDate = @"creationDateString";
static NSString* const ALEntryFilterPrimaryKeyPathLastActivityDate = @"lastActivityDateString";


@implementation ALEntryFilter

-(NSString *)intermediateFilterKeyPath {
    if ([self filterTypeValue] != ALEntryFilterTag)
        return nil;
    return [NSString stringWithFormat:@"arrangedObjects.@distinctUnionOfSets.%@", ALEntryFilterIntermediateKeyPathTag];
}

-(NSString *)primaryFilterKeyPath {
    NSString *primaryKeyPath = nil;
    switch ([self filterTypeValue]) {
        case ALEntryFilterTag:
            primaryKeyPath = ALEntryFilterPrimaryKeyPathTag;
            break;
        case ALEntryFilterCreator:
            primaryKeyPath = ALEntryFilterPrimaryKeyPathCreator;
            break;
        case ALEntryFilterCreationDate:
            primaryKeyPath = ALEntryFilterPrimaryKeyPathCreationDate;
            break;
        case ALEntryFilterLastActivityDate:
            primaryKeyPath = ALEntryFilterPrimaryKeyPathLastActivityDate;
            break;
        default:
            return nil;
    }
    return [NSString stringWithFormat:@"arrangedObjects.%@", primaryKeyPath];
}

@end
